package com.holyant.goods.dto.query;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.holyant.goods.dto.GdsSettlementScopeDto;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 商品指引价 echarts 图 查询dto
 *
 * @author zgx *
 * @date 2022年06月28日 9:42
 */
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class GdsSettlementScopeQueryDto {

    private static final Integer size = 30;
    private Map<Integer, List<String>> stringObjectMap = new HashMap<>();

    @NotBlank(message = "sku编码不能为空!")
    @ApiModelProperty(value = "sku编码")
    private String skuCode;
    /**
     * 生效时间
     */
    @NotNull(message = "生效时间不能为空!")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "生效时间")
    private LocalDate effectiveTimeStart;
    /**
     * 失效时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "失效时间")
    private LocalDate effectiveTimeEnd;

    @NotNull(message = "币种不能为空!")
    @ApiModelProperty(value = "币种")
    private Integer curType;

    @NotNull(message = "报价方式不能为空!")
    @ApiModelProperty(value = "报价方式 10：包邮不包税，20：包邮包税，30: 不包邮不包税")
    private Integer quoteMethod;

    @NotNull(message = "渠道类型不能为空!")
    @ApiModelProperty(value = "渠道类型10 c2p 20 pop 30 b2b(hk) 40b2b(mo) 50ka 60 wm")
    private Integer salesChannel;

    public void initMap() {
        for (int i = 1; i <= 6; i++) {
            stringObjectMap.put(i, new ArrayList<>());
        }
    }

    public void put(Integer code, String val) {
        stringObjectMap.get(code).add(val);
    }

    public List<String> get(Integer code) {
        return stringObjectMap.get(code);
    }


    public List<GdsSettlementScopeDto> getSettlementScope() {
        List<GdsSettlementScopeDto> series = new ArrayList<>(6);
        for (Map.Entry<Integer, List<String>> integerListEntry : stringObjectMap.entrySet()) {
            if (CollectionUtils.isNotEmpty(integerListEntry.getValue())) {
                series.add(GdsSettlementScopeDto.builder().name(integerListEntry.getKey() + "pcs")
                        .type("line")
                        .step("end")
                        .data(integerListEntry.getValue()).build());
            }
        }

        return series;
    }


    public void copyListLastData() {
        // 数组每个增加30天
        for (int j = 1; j <= 6; j++) {
            for (int i = 0; i < size;i++) {
                put(j, get(j).get(get(j).size() - 1));
            }
        }
    }


}
